package com.ybkj.chat.module.login.presenter;

import android.content.Context;

import com.ybkj.chat.base.BaseRxPresenter;
import com.ybkj.chat.common.Constants;
import com.ybkj.chat.module.login.view.PhoneCodeLoginView;
import com.ybkj.chat.utils.FormCheckUtil;

import javax.inject.Inject;

/**
 * author : ywh
 * date : 2019/3/6 19:34
 * description :
 */
public class PhoneCodeLoginPresenter extends BaseRxPresenter<PhoneCodeLoginView> {
    @Inject
    public PhoneCodeLoginPresenter(Context context) {
        super(context);
    }

    @Override
    public void onSuccess(Object response, int tag) {
        switch (tag) {
            //获取验证码
            case Constants.REQUEST_CODE_1:
                mView.CodeSuccess();
                break;
            case Constants.REQUEST_CODE_2:

                break;
        }
    }

    /**
     * 获取验证码
     *
     * @param phone
     */
    public void getPhoneCode(String phone) {
        if (FormCheckUtil.phoneCheck(phone)) {
            return;
        }
        //获取验证码
        sendHttpRequest(apiService.getVerificationCode(phone), Constants.REQUEST_CODE_1);
    }

    /**
     * 手机号登录
     *
     * @param phone1
     * @param code
     */
    public void login(String phone1, String code) {
        if (FormCheckUtil.phoneCheck(phone1)) {
            return;
        }

        if (FormCheckUtil.codeCheck(code)) {
            return;
        }
        //手机号码登录
        sendHttpRequest(apiService.phoneNumberLogin(phone1, code, 1), Constants.REQUEST_CODE_2);
    }
}
